<template>
  <div class="subject-add addButton">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>教务管理</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/education/subject/list' }">科目管理</el-breadcrumb-item>
      <el-breadcrumb-item>添加科目</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="form">
      <el-form ref="form" :model="form" label-width="120px" size="small" :rules="rules">
        <el-form-item label="科目名称:" prop="name">
          <el-input v-model="form.name" placeholder="请输入科目名称" style="width:230px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="background:#ff8b00;color:#fff" @click="onSubmit" :disabled="isDisabled">提交</el-button>
          <el-button style="background:#999999;color:#fff" @click="resetForm('form')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

</template>
<script>
export default {
  data() {
    return {
      form: {
        name: "",
      },
      intentionList: [],
      rules: {
        name: [
          { required: true, message: "请填写科目名称", trigger: "blur" },
          { min: 2, max: 50, message: "长度在 2 到 50 个字符", trigger: "blur" }
        ]
      },
      isDisabled: false,
    };
  },
  methods: {
    onSubmit() {
      this.$refs["form"].validate(async (valid) => {
        if (valid) {
          this.isDisabled = true
          this.$api.education.subjectAdd({
            name:this.form.name
          }).then((res)=>{
             this.$message.success("添加成功");
             this.resetForm()
          }).catch(err=>{
            this.resetForm()
          })
        }
      });
    },
    resetForm() {
      this.form = {
        name: "",
      };
      this.isDisabled = false;
    }
  },
};
</script>
<style scoped>
.subject-add {
  padding: 30px;
}

.subject-add .form {
  max-width: 700px;
  margin: 30px 0px;
}

.subject-add .img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: 230px;
  max-height: 130px;
  transform: translate(-50%, -50%);
  z-index: 0;
}
</style>
